/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package filecopier.gui.scripteditor;

import javax.swing.JDialog;
import filecopier.script.Script;
import filecopier.options.Options.CopyScriptType;
import java.beans.PropertyChangeListener;

/**
 *
 * @author david
 */
public class ScriptEditorDialog extends JDialog {

    public ScriptEditorDialog(final CopyScriptType copyScriptType, final Script script, final PropertyChangeListener pcl, boolean modal) {
        super(filecopier.Singleton.getInstance().getFrame(), (script.getScriptName() != null ? script.getScriptName() : "Untitled"), modal);
        initialize(copyScriptType, script, pcl);
    }

    private void initialize(final CopyScriptType copyScriptType, final Script script, final PropertyChangeListener pcl) {
        ScriptEditorPanel scriptEditorPanel = new ScriptEditorPanel(this, copyScriptType, script);
        ButtonPanel buttonPanel = new ButtonPanel();
        scriptEditorPanel.getPropertyChangeSupport().addPropertyChangeListener("scriptChanged", buttonPanel);
        if (pcl != null) {
            scriptEditorPanel.getPropertyChangeSupport().addPropertyChangeListener("scriptName", pcl);
        }
        buttonPanel.addBtnActionListener(scriptEditorPanel);

        getContentPane().setLayout(new java.awt.BorderLayout());
        this.add(buttonPanel, java.awt.BorderLayout.WEST);
        this.add(scriptEditorPanel, java.awt.BorderLayout.CENTER);
        this.setDefaultCloseOperation(javax.swing.JFrame.DO_NOTHING_ON_CLOSE);
        this.addWindowListener(scriptEditorPanel);
        this.setIconImage(filecopier.Singleton.getInstance().getImage16());
        this.pack();
        this.setVisible(true);
    }
}
